package com.hmall.trade.listener;

import com.hmall.trade.service.IOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@RequiredArgsConstructor
@Component
public class PayStatusListener {
    //durable = "true"，持久化队列，重启后消息还在，持久化队列在服务器重启后仍然会保留队列中的消息
    //这是RabbitMQ中保证消息可靠性的重要配置之一
    private final IOrderService orderService;
    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "pay.status.queue", durable = "true"),
            exchange = @Exchange(value = "pay.direct", type = ExchangeTypes.TOPIC),
            key = "pay.success"))
    public void payStatus(Long id) {
        orderService.markOrderPaySuccess(id);
    }
}
